﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Drawing;

namespace Ma_di_tuan
{
    public class Knight : Piece// chu yeu lay phuong thuc ve string Knight
    {

        /*
         * Doi tuong knight co vitri location va danh sach ca o no da m_di qua (Listmoves)
         */
        public Knight(string name,int m_x,int m_y)
        {
            Name = name;
            m_location = new Location()
            {
                Row = m_x-1,
                Rank = m_y-1
            };
            //  ListMoves la danh sach cac o ma no da m_di qua
            ListMoves = new List<Location>(1);
            ListMoves.Add(m_location);
        }

        public override List<Location> GetAvailableMoves(Location Loc, Size Dimension)
        {
            List<Location> ListpossibleMoves = new List<Location>(1);// capacity=1
            int newRow = Loc.Row + 2;
            int newRank = Loc.Rank - 1;
            if (Loc.ValidLocation(newRow, newRank, Dimension))
                ListpossibleMoves.Add(new Location() { Row = newRow, Rank = newRank });

            newRow = Loc.Row + 2;
            newRank = Loc.Rank + 1;
            if (Loc.ValidLocation(newRow, newRank, Dimension))
                ListpossibleMoves.Add(new Location() { Row = newRow, Rank = newRank });

            newRow = Loc.Row + 1;
            newRank = Loc.Rank + 2;
            if (Loc.ValidLocation(newRow, newRank, Dimension))
                ListpossibleMoves.Add(new Location() { Row = newRow, Rank = newRank });

            newRow = Loc.Row + 1;
            newRank = Loc.Rank - 2;
            if (Loc.ValidLocation(newRow, newRank, Dimension))
                ListpossibleMoves.Add(new Location() { Row = newRow, Rank = newRank });

            newRow = Loc.Row - 1;
            newRank = Loc.Rank - 2;
            if (Loc.ValidLocation(newRow, newRank, Dimension))
                ListpossibleMoves.Add(new Location() { Row = newRow, Rank = newRank });

            newRow = Loc.Row - 1;
            newRank = Loc.Rank + 2;
            if (Loc.ValidLocation(newRow, newRank, Dimension))
                ListpossibleMoves.Add(new Location() { Row = newRow, Rank = newRank });

            newRow = Loc.Row - 2;
            newRank = Loc.Rank - 1;
            if (Loc.ValidLocation(newRow, newRank, Dimension))
                ListpossibleMoves.Add(new Location() { Row = newRow, Rank = newRank });

            newRow = Loc.Row - 2;
            newRank = Loc.Rank + 1;
            if (Loc.ValidLocation(newRow, newRank, Dimension))
                ListpossibleMoves.Add(new Location() { Row = newRow, Rank = newRank });

            return ListpossibleMoves;//List<location>
        }
    }
}
